package com.lineage.server.command.executor;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_HPMeter;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1HpBar implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1HpBar.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1HpBar();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    if (arg.equalsIgnoreCase("pc")) {
      pc.setSkillEffect(2003, 0);
    } else if (arg.equalsIgnoreCase("on")) {
      pc.setSkillEffect(2001, 0);
    } else if (arg.equalsIgnoreCase("off")) {
      pc.removeSkillEffect(2001);
      Iterator<L1Object> iterator = pc.getKnownObjects().iterator();
      while (iterator.hasNext()) {
        L1Object obj = iterator.next();
        if (pc.isGmHpBarTarget(obj))
          pc.sendPackets((ServerBasePacket)new S_HPMeter(obj.getId(), 255)); 
      } 
    } else {
      _log.error("错误的GM指令格式: " + getClass().getSimpleName() + " 执行的GM:" + pc.getName());
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
    } 
  }
  
  public static boolean isHpBarTarget(L1Object obj) {
    return !(!(obj instanceof com.lineage.server.model.Instance.L1MonsterInstance) && !(obj instanceof L1PcInstance) && !(obj instanceof com.lineage.server.model.Instance.L1SummonInstance) && 
      !(obj instanceof com.lineage.server.model.Instance.L1PetInstance));
  }
}
